﻿using System;
using PRDP.DS.Tree;

public partial class Ontology : PRDP.Page.BL.OntologyBL
{
    //每行显示的节点数
    public readonly static int COLUMN_COUNT = 5;
    //每个父节点最多显示子节点行数
    public readonly static int ROW_COUNT = 5;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["path"] == null)
        {
            currentNode = root;
            hfTreePath.Value = "0";
        }
        else
        {
            currentNode = root.travelTreeByTpath(Request.QueryString["path"]);
            hfTreePath.Value = Request.QueryString["path"];
        }
    }

    /**
    public static PRDP.DS.Tree.TreeNode deSerializeTreeNode(string treeName)
    {
        PRDP.DS.Tree.TreeNode node;
        using (FileStream fs = new FileStream("d:/pubmed_category/tree_web/" + treeName + ".tree", FileMode.Open))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            node = (PRDP.DS.Tree.TreeNode)formatter.Deserialize(fs);
        }
        return node;
    }
    

    public static void mergerTree()
    {
        Tree tree = new Tree("All MeSH Categories");
        List<int> pubmedUrls = new List<int>();
        pubmedUrls.Add(1000065);
        pubmedUrls.Add(1000066);
        pubmedUrls.Add(1000067);
        pubmedUrls.Add(1000068);
        pubmedUrls.Add(1000069);
        pubmedUrls.Add(1000070);
        pubmedUrls.Add(1000071);
        pubmedUrls.Add(1000072);
        pubmedUrls.Add(1000073);
        pubmedUrls.Add(1000074);
        pubmedUrls.Add(1000075);
        pubmedUrls.Add(1000076);
        pubmedUrls.Add(1000077);
        pubmedUrls.Add(1000078);
        pubmedUrls.Add(1000082);
        pubmedUrls.Add(1000086);
        pubmedUrls.Add(1000088);
        pubmedUrls.Add(1000089);
        pubmedUrls.Add(1000090);
        foreach (int categoryId in pubmedUrls)
        {
            tree.addChild(deSerializeTreeNode(categoryId.ToString()));
        }
        serializeTree(tree, "Ontology");
    }

    static void getOntology()
    {
        List<int> pubmedUrls = new List<int>();
        pubmedUrls.Add(1000065);
        pubmedUrls.Add(1000066);
        pubmedUrls.Add(1000067);
        pubmedUrls.Add(1000068);
        pubmedUrls.Add(1000069);
        pubmedUrls.Add(1000070);
        pubmedUrls.Add(1000071);
        pubmedUrls.Add(1000072);
        pubmedUrls.Add(1000073);
        pubmedUrls.Add(1000074);
        pubmedUrls.Add(1000075);
        pubmedUrls.Add(1000076);
        pubmedUrls.Add(1000077);
        pubmedUrls.Add(1000078);
        pubmedUrls.Add(1000082);
        pubmedUrls.Add(1000086);
        pubmedUrls.Add(1000088);
        pubmedUrls.Add(1000089);
        pubmedUrls.Add(1000090);
        foreach (int categoryId in pubmedUrls)
        {
            OntologyCrawler oc = new OntologyCrawler(categoryId, true, "All MeSH Categories");
            oc.crawler();
            //oc.Root.Child.toDatabase(-1);
            //MyFileHelper.writeStringToFile(oc.Root.Child.toString(), "d:/pubmed_category/" + oc.Root.Name + ".txt");
            serializeTreeNode(oc.Root, categoryId.ToString());
        }
    }

    public static void serializeTreeNode(PRDP.DS.Tree.TreeNode treeNode, string treeName)
    {
        using (FileStream fs = new FileStream("d:/pubmed_category/tree_web/" + treeName + ".tree", FileMode.Create))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(fs, treeNode);
        }
    }

    public static void serializeTree(Tree tree, string treeName)
    {
        using (FileStream fs = new FileStream("d:/pubmed_category/tree_web/" + treeName + ".tree", FileMode.Create))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(fs, tree);
        }
    }
    **/
}
